using System.Collections;
using System.ComponentModel;
using MyFramework.Singleton;
using UnityEngine;
using UnityEngine.Events;

namespace MyFramework.Mono
{
    /// <summary>
    /// 1.提供给外部添加帧更新事件的方法
    /// <br></br>
    /// 2.提供给外部添加协程的方法
    /// </summary>
    public class MonoManager : Singleton<MonoManager>
    {
        private readonly MonoController _monoController;

        public MonoManager()
        {
            GameObject tempObj = new GameObject("MonoController");
            _monoController = tempObj.AddComponent<MonoController>();
        }

        /// <summary>
        /// 添加帧更新事件
        /// （令不继承MonoBehavior的类具备帧更新的能力）
        /// </summary>
        /// <param name="fun"></param>
        public void AddUpdateListener(UnityAction fun)
        {
            _monoController.AddUpdateListener(fun);
        }

        /// <summary>
        /// 移除帧更新事件
        /// </summary>
        /// <param name="fun"></param>
        public void RemoveUpdateListener(UnityAction fun)
        {
            _monoController.RemoveUpdateListener(fun);
        }

        public Coroutine StartCoroutine(string methodName)
        {
            return _monoController.StartCoroutine(methodName);
        }

        public Coroutine StartCoroutine(IEnumerator routine)
        {
            return _monoController.StartCoroutine(routine);
        }

        public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
        {
            return _monoController.StartCoroutine(methodName, value);
        }

        public Coroutine StartCoroutine_Auto(IEnumerator routine)
        {
            return _monoController.StartCoroutine(routine);
        }

        public void StopAllCoroutines()
        {
            _monoController.StopAllCoroutines();
        }

        public void StopCoroutine(IEnumerator routine)
        {
            _monoController.StartCoroutine(routine);
        }

        public void StopCoroutine(Coroutine routine)
        {
            _monoController.StopCoroutine(routine);
        }

        public void StopCoroutine(string methodName)
        {
            _monoController.StopCoroutine(methodName);
        }
    }

}